package com.zwj.web;

import com.zwj.bean.User;
import com.zwj.service.Impl.UserServiceImpl;
import com.zwj.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zwj
 * @create 2021-05-12-19:36
 */
public class LoginServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求的参数
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        User login = userService.login(new User(null, username, password, null));
        //判断用户
        if(login != null){
            req.getRequestDispatcher("/pages/user/login_success.jsp").forward(req,resp);
        }else {
            req.setAttribute("msg","用户名或密码错误");
            req.setAttribute("username",username);
            System.out.println("bagayalu");
            req.getRequestDispatcher("/pages/user/login.jsp").forward(req,resp);
        }
    }
}
